The workflow for several of the trading processes between the client UI application and the GAIN Capital trading services are shown in the following annotated sequence diagrams. The diagrams illustrate the general flow of calls and responses for the C# library and client UI during trading processes such as placing a trade, creating an entry order, or account login. The annotations for the diagram present additional information about the process.
Login to the trading account and retrieve the account information:
Perform account login by calling
CiApi.Instance.Login(username, password, tradingApiBaseUri);
When login is successful, retrieve the account information as follows
AccountInformationResponseDTO accountInfoResponse = CiApi.Instance.ServiceManager.AccountInformationService.GetClientAndTradingAccount()
The following sequence shows the process flow to return all FX markets to the user, as an example to populate a market grid with constantly updating prices.
Populate the market grid and subscribe to price streams to update the grid appropriately:
The following market search returns all FX markets for the user account
IList<ApiMarketDTO> apiMarketDtoList = CiApi.Instance.ServiceManager
.CfdMarketService.ListCfdMarkets("", true, true, accountInfoResponse.ClientAccountId, 70).Markets;
Read the markets returned from the search into a list
List<int> marketIdList = apiMarketDtoList.Select(apiMarketDTO => apiMarketDTO.MarketId).ToList();
Retrieve the market information for each of the FX markets
ListMarketInformationResponseDTO listMarketInformationResponseDTO = ciApi.ServiceManager.MarketInformationService.ListMarketInformation(marketIdList);
Preparation for Lightstreamer subscription
CiApi.Instance.StreamingManager.StreamingUrl = lightStreamerUrl;
Subscribe to price stream
CiApi.Instance.StreamingManager.Streams.PriceStream.SubscribeToMarketPriceList(marketIdList);
If required to mock the CiApi, inject the instance into your client class, otherwise, you substitute _ciApi for CiApi.Instance. For example,
public MarketGridViewModel(ICiApi ciApi)
{
_ciApi = ciApi;
}